#!/bin/sh

#  iIHS.sh
#
#  Created by iGhibli on 2021/06/29.
#  Copyright © 2021年 All rights reserved.


# echo iIHS.sh start...

ihs_dir="/Users/lindada/Documents/GitHub/IHS/Images"
res_path=$1

# 切换到项目路径
cd $ihs_dir

# 创建当日文件夹
dir_name=$(date +%Y%m%d)

if [ ! -d $dir_name ];then
    mkdir $dir_name
fi 

# 拷贝目标图片
timestamp=$(date +%s)
tmp=${res_path##*/}
file_name=${tmp%.*}
extension="${res_path##*.}"
dst_file_name=${file_name}"_"${timestamp}"."${extension}
dst_path=${ihs_dir}"/"${dir_name}"/"${dst_file_name}
cp $res_path $dst_path

# echo $dir_name
# echo $timestamp
# echo $file_name
# echo $extension
# echo "目标图片路径：${dst_path}"

# Git操作
git add .
git commit -m "Add image(${dst_file_name})."
git push origin master

# 返回结果
echo "+Done+${file_name}+${dir_name}/${dst_file_name}"